#include "Eventfd.hpp"
#include "Thread.hpp"

#include <stdlib.h>
#include <time.h>
#include <unistd.h>

#include <iostream>
#include <functional>

using std::cout;
using std::endl;

class Task
{
public:
    void process()
    {
        ::srand(::time(NULL));
        int num = rand() % 100;
        cout << "produce a num:" << num << endl;
    }

};

int main()
{
    Eventfd eventfd(std::bind(&Task::process, Task()));
    //eventfd.start();//start方法的调用应该放到子线程中进行
                    
    wd::Thread thread(std::bind(&Eventfd::start, &eventfd));
    thread.start();//开启子线程的运行

    int cnt =10;
    while(cnt-- > 0) {
        //主线程中每一秒钟通知一次
        eventfd.wakeup();
        cout << "cnt " << cnt << endl;
        sleep(1);
    }

    eventfd.stop();
    thread.join();

    return 0;
}

